﻿using System;
using System.Globalization;
using System.Text.RegularExpressions;

namespace OpenWaves.EPiServer.Localization.Model
{
    public class NamingConvention
    {
        private const string InvalidCharsPattern = @"[^a-zA-Z0-9]";
        private const string UpperLetters = @"[A-Z]";

        public static string GenerateIdentifier(string name)
        {
            if (String.IsNullOrEmpty(name))
            {
                return name;
            }

            string identifierWithoutInvalidChars =
                Regex.Replace(Regex.Replace(name, InvalidCharsPattern, " "), UpperLetters, " ${0}");

            return CultureInfo.InvariantCulture.TextInfo
                              .ToTitleCase(identifierWithoutInvalidChars)
                              .Replace(" ", "");
        }
    }
}